package com.ma.logica;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.Disposable;

public class Assets implements Disposable{

	public static final String TAG = Assets.class.getName();

	public static final Assets instance = new Assets();

	private AssetManager assetManager;

	// libgdx logo comes with libgdx
	public AssetImages images;
	
	// mad with http://www.bfxr.net/
	public AssetSounds sounds;
	
	// music from http://www.nosoapradio.us/ THANKS DST
	public AssetMusic music;

	// singleton: prevent instantiation from other classes
	private Assets() {
	}

	public class AssetImages {
		public final Texture astExplosion;
		public final Texture asteroideTexture;
		public final Texture coinTexture;
		public final Texture botonesTexture;
		public final Texture misilTexture;
		public final Texture fondoTexture;
		public final Texture sonidoTexture;
		public final Texture diamanteTexture;
		public final Texture calaveraTexture;
		public final Texture corazonTexture;

		public AssetImages() {
			System.out.println("AssetsImages");
			astExplosion = new Texture(Gdx.files.internal("data/imagenes/ast_explosion.png"));
			asteroideTexture = new Texture(Gdx.files.internal("data/imagenes/asteroide.png"));
			coinTexture = new Texture(Gdx.files.internal("data/imagenes/pez_coin.png"));
			botonesTexture = new Texture(Gdx.files.internal("data/imagenes/botones.png"));
			misilTexture = new Texture(Gdx.files.internal("data/imagenes/misil.png"));
			fondoTexture = new Texture(Gdx.files.internal("data/imagenes/fondo.png"));
			sonidoTexture = new Texture(Gdx.files.internal("data/imagenes/sonido.png"));
			diamanteTexture = new Texture(Gdx.files.internal("data/imagenes/diamante.png"));
			calaveraTexture = new Texture(Gdx.files.internal("data/imagenes/calavera.png"));
			corazonTexture = new Texture(Gdx.files.internal("data/imagenes/corazon.png"));
		}
	}

	public class AssetSounds {
		public final Sound coin;
		public final Sound boomSound;
		public final Sound diamanteSound;

		public AssetSounds(AssetManager am) {
			System.out.println("AssetsSounds");
			coin = am.get("data/musica/coin_colected.mp3", Sound.class);
			boomSound = am.get("data/musica/boom1.mp3", Sound.class);
			diamanteSound = am.get("data/musica/diamante.mp3", Sound.class);
		}
	}

	public class AssetMusic {
		public final Music mFondo;

		public AssetMusic(AssetManager am) {
			System.out.println("AssetsMusic");
			mFondo = am.get("data/musica/musica_fondo.mp3", Music.class);
		}
	}

	public void init(AssetManager assetManager) {
		System.out.println("init");
		this.assetManager = assetManager;

		// load texture
		assetManager.load("data/imagenes/fondo.png", Texture.class);
		assetManager.load("data/imagenes/asteroide.png", Texture.class);
		assetManager.load("data/imagenes/ast_explosion.png", Texture.class);
		assetManager.load("data/imagenes/pez_coin.png", Texture.class);
		assetManager.load("data/imagenes/botones.png", Texture.class);
		assetManager.load("data/imagenes/misil.png", Texture.class);
		assetManager.load("data/imagenes/sonido.png", Texture.class);
		assetManager.load("data/imagenes/diamante.png", Texture.class);
		assetManager.load("data/imagenes/calavera.png", Texture.class);
		assetManager.load("data/imagenes/corazon.png", Texture.class);
		// load sounds
		assetManager.load("data/musica/boom1.mp3", Sound.class);
		assetManager.load("data/musica/coin_colected.mp3", Sound.class);
		assetManager.load("data/musica/diamante.mp3", Sound.class);
		// load music
		assetManager.load("data/musica/musica_fondo.mp3", Music.class);

		Gdx.app.debug(TAG,"# of assets loaded: " + assetManager.getAssetNames().size);
		System.out.println("# of assets loaded: " + assetManager.getAssetNames().size);
		for (String a : assetManager.getAssetNames()) {
			Gdx.app.debug(TAG, "asset: " + a);
			System.out.println("asset: " + a);
		}
	}

	public void assetsGet(AssetManager assetManager){
		images = new AssetImages();
		sounds = new AssetSounds(assetManager);
		music = new AssetMusic(assetManager);
	}
	
	@Override
	public void dispose() {
		System.out.println("assets dispossing...");
		assetManager.dispose();
	}

}